﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace TileMapEditor
{
    public enum ObjUIType
    {
        [EnumDescription("无")]
        None = 0,
        [EnumDescription("战斗预览")]
        UI_ShowEnemyPreview = 1,
        [EnumDescription("遗物选择")]
        UI_ShowBuffPickUp = 2,
        [EnumDescription("英雄选择（马车）")]
        UI_ShowHeroPickUp = 3,
        [EnumDescription("特定对话框")]
        UI_ShowCustomConfirm = 4,
        [EnumDescription("进度宝箱")]
        UI_RewardBox = 5,
        [EnumDescription("动态难度敌人")]
        UI_DynamicLevelEnemy = 10,
        [EnumDescription("障碍物")]
        UI_Block = 99,
        [EnumDescription("可通行物件（陷阱）")]
        UI_Trap = 100
    }

    [System.Serializable]
    public class GameObjData : MonoBehaviour
    {
        public TileObjPrefab prefab;

        public int id;
        public bool canPass = true;
        public bool visible = true;
        public bool isRewardBox = false;//是否进度宝箱
        public bool isHpSpring = false;//是否泉水（会受到遗物加成）如果是则type = 6 否则 type = uiType
        public int dynamicLevel = 1;
        [ReadOnly]
        public Vector2Int ipos;
        [ReadOnly]
        public string assetPath;
        [ReadOnly]
        public string assetName;
        [ReadOnly]
        public string spineEffect;
        [ReadOnly]
        public bool isEffectShow;
        [ReadOnly]
        public bool isHideOriginSprite = true;
        [ReadOnly]
        public bool isShowEffectOnRemove = true;

        public int uiShowType = 0;
        [HideInInspector]
        [SerializeField]
        public List<int> uiParams;
        [SerializeField]
        public List<TriggerEffect> triggerEffects;

        public bool removeAfterTriggerIsOver;

        [ReadOnly]
        public int layerFix;
        [ReadOnly]
        public bool overridePosition = false;
        [HideInInspector]
        public Vector3 objPosition;
        [HideInInspector]
        public Vector3 objRotation;
        [HideInInspector]
        public Vector3 objScale;

        [HideInInspector]
        public int layer = 6;
    }

    [System.Serializable]
    public class GameObjDataObject
    {
        [ReadOnly]
        public int id;
        [ReadOnly]
        public bool canPass = true;
        [ReadOnly]
        public bool visible = true;
        [ReadOnly]
        public bool isRewardBox = false;
        [ReadOnly]
        public bool isHpSpring = false;
        [ReadOnly]
        public Vector2Int ipos;
        [ReadOnly]
        public string assetPath;
        [ReadOnly]
        public string assetName;
        [ReadOnly]
        public int uiShowType = 0;
        [ReadOnly]
        public List<int> uiParams;
        [ReadOnly]
        public string spineEffect;
        [ReadOnly]
        public bool isEffectShow = true;
        [ReadOnly]
        public int layer = 6;
        [ReadOnly]
        public bool isHideOriginSprite;
        [ReadOnly]
        public bool isShowEffectOnRemove;

        [ReadOnly]
        public List<TriggerEffectData> triggerEffects;
        [ReadOnly]
        public bool removeAfterTriggerIsOver;

        [ReadOnly]
        public int layerFix;
        [ReadOnly]
        public bool overridePosition = false;
        [HideInInspector]
        public Vector3 objPosition;
        [HideInInspector]
        public Vector3 objRotation;
        [HideInInspector]
        public Vector3 objScale;

        public int dynamicLevel = 1;

        public GameObjDataObject(GameObjData objData)
        {
            id = objData.id;
            canPass = objData.canPass;
            visible = objData.visible;
            isRewardBox = objData.isRewardBox;
            isHpSpring = objData.isHpSpring;
            ipos = objData.ipos;
            assetPath = objData.assetPath;
            assetName = objData.assetName;
            if(objData.triggerEffects!=null && objData.triggerEffects.Count > 0)
            {
                triggerEffects = new List<TriggerEffectData>();
                foreach(var data in objData.triggerEffects)
                {
                    triggerEffects.Add(new TriggerEffectData(data));
                }
            }
            removeAfterTriggerIsOver = objData.removeAfterTriggerIsOver;
            uiShowType = objData.uiShowType;
            uiParams = objData.uiParams;
            spineEffect = objData.spineEffect;
            isEffectShow = objData.isEffectShow;
            layer = objData.layer;
            isHideOriginSprite = objData.isHideOriginSprite;
            isShowEffectOnRemove = objData.isShowEffectOnRemove;
            overridePosition = objData.overridePosition;
            layerFix = objData.layerFix;
            objPosition = objData.objPosition;
            objRotation = objData.objRotation;
            objScale = objData.objScale;
            dynamicLevel = objData.dynamicLevel;
        }

        public static string[] ShowUITypeNames = EnumParser.GetEnumDescriptions(typeof(ObjUIType));
        public static int[] ShowUITypes = EnumParser.GetEnumValues(typeof(ObjUIType));
    }
}
